package com.demo.tool;

import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;

@Component
public class Base64Strategy {

    //加密方法
    public String encode(String password) throws UnsupportedEncodingException{

        byte[] encode = Base64.getEncoder().encode(password.getBytes(StandardCharsets.UTF_8));
        return new String(encode,"UTF-8");
    }

    //解密方法
    public String decode(String encode) throws UnsupportedEncodingException{

        byte[] decode = Base64.getDecoder().decode(encode.getBytes(StandardCharsets.UTF_8));
        return new String(decode,"UTF-8");
    }
}
